(define-module (fiio kubectl)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix build-system trivial)
  #:use-module (guix download)
  #:use-module (guix packages)
  #:use-module (gnu packages base)
  #:use-module (gnu packages compression))

(define-public kubectl
  (package
    (name "kubectl")
    (version "1.16.3")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "https://storage.googleapis.com/kubernetes-release/release/"
                    "v" version 
                    "/bin/linux/amd64/kubectl"))
              (sha256
               (base32
                "0b8grhjry0ndbxgiraxhbf0mwr37v5zpajq265gmfhap8131pvfd"))))
    (build-system trivial-build-system)
    (arguments
     `(#:builder (begin
                   (use-modules (guix build utils))
                   (let* ((source (assoc-ref %build-inputs "source"))
                          (out    (assoc-ref %outputs "out"))
                          (bindir (string-append out "/bin"))
                          (target (string-append bindir "/kubectl")))
                     (mkdir-p bindir)
                     (copy-file source target)
                     (chmod target #o555)
                     #t))
       #:modules ((guix build utils))))
    (supported-systems '("x86_64-linux"))
    (home-page "https://kubernetes.io")
    (synopsis "Command line interface for running commands against Kubernetes clusters")
    (description "Kubectl is a command line interface for running
commands against Kubernetes clusters. kubectl looks for a file named
config in the $HOME/. kube directory. You can specify other kubeconfig
files by setting the KUBECONFIG environment variable or by setting the
--kubeconfig flag.")
    (license license:asl2.0)))

(define-public kube-helm
  (package
    (name "kube-helm")
    (version "3.0.0")
    (source (origin
              (method url-fetch)
              (uri (string-append
                    "https://get.helm.sh/helm-v" version "-linux-amd64.tar.gz"))
              (sha256
               (base32
                "1p60v2ij06nxa60ks9l1qgb3vvz19f93mf9cgcfjn1k3lb6gvq8h"))))
    (build-system trivial-build-system)
    (arguments
     '(#:builder (begin
                   (use-modules (guix build utils))
                   (let* ((source  (assoc-ref %build-inputs "source"))
                          (tar     (assoc-ref %build-inputs "tar"))
                          (xz      (assoc-ref %build-inputs "xz"))
                          (gzip      (assoc-ref %build-inputs "gzip"))
                          (fname   "linux-amd64/helm")
                          (out     (assoc-ref %outputs "out"))
                          (bindir  (string-append out "/bin"))
                          (target  (string-append bindir "/helm")))
                     (mkdir-p bindir)
                     (set-path-environment-variable "PATH" '("bin")
                                                    (list tar xz gzip))
                     (invoke "tar" "-C" bindir
                             "--strip-components=1"
                             "-xvf" source fname)  
                     (chmod target #o555)
                     #t))
       #:modules ((guix build utils))))
    (native-inputs
     `(("tar" ,tar)
       ("gzip" ,gzip)
       ("xz" ,xz)))
    (supported-systems '("x86_64-linux"))
    (home-page "https://helm.sh")
    (synopsis "The Kubernetes package manager")
    (description "This package is a tool for managing Charts.  Charts
are packages of pre-configured Kubernetes resources.")
    (license license:asl2.0)))
